$(document).ready(function(){
	//All names of required fields here.
	required = ["pqty", "uname", "ucontact", "uphone", "uaddress"];
	//Email rquired
	uemail = $("#uemail");
	errornotice = $("#error");
	//Message show up in input box
	emptyerror = "Required field.";
	emailerror = "Invalid e-mail.";

	$("#theform").submit(function(){	
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = $('#'+required[i]);
			if ((input.val() == "") || (input.val() == emptyerror)) {
				input.addClass("required");
				input.val(emptyerror);
				errornotice.fadeIn(750);
			} else {
				input.removeClass("required");
			}
		}
		// Validate the e-mail.
		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(uemail.val())) {
			uemail.addClass("required");
			uemail.val(emailerror);
		}

		//if any inputs on the page have the class 'required' the form will not submit
		if ($(":input").hasClass("required")) {
			return false;
		} else {
			errornotice.hide();
			return true;
		}
	});
	
	// Clears any fields in the form when the user clicks on them
	$(":input").focus(function(){		
	   if ($(this).hasClass("required") ) {
			$(this).val("");
			$(this).removeClass("required");
	   }
	});
});	



//limit number characters
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

//number restrict area
function numbersonly(fb_account, e, dec)
{
var key;
var keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((('0123456789').indexOf(keychar) > -1))
   return true;
// decimal point jump
else if (dec && (keychar == ".")) {
   fb_account.form.elements[dec].focus();
   return false;
   }
else
   return false;
}